package com.service.impl;

import com.dao.ActivityDevMapper;
import com.entity.Data;
import com.entity.Device;
import com.entity.Paging;
import com.entity.Vehicle;
import com.github.pagehelper.PageHelper;
import com.service.ActivityDevService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
@Service
public class ActivityDevServiceImpl implements ActivityDevService {
    @Autowired
    private ActivityDevMapper activityDevMapper;
    public boolean addVehicle(List<Vehicle> vehicles){
        if (activityDevMapper.addVehicle(vehicles)!=0){
            return true;
        }else {
            return false;
        }
    }
    public int addDevice(List<Device> devices){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");


        int  num = activityDevMapper.addDevice(devices);
        return num;
    }
    public List<Vehicle> selectVehicles(Paging paging){
        PageHelper.startPage(paging.getPage(), paging.getLimit());
        return activityDevMapper.selectVehicles();
    }

    public List<Device> sleectDevices(Paging paging){
        PageHelper.startPage(paging.getPage(), paging.getLimit());
        return  activityDevMapper.sleectDevices();
    }
    public List<Vehicle> selectVehiclesByproID(int proID){
            return  activityDevMapper.selectVehiclesByproID(proID);
    }

    public  Object deleteVehicle(List<Vehicle> list ){
        Data data = new Data();
        for(Vehicle vehicle:list){
            if (activityDevMapper.deleteVehicle(vehicle) == 0){
             data.setState(false);
             data.setError("删除失败！无此设备。");
             return data;
         }
        }
        data.setState(true);
       return data;
    }

   // public  Object deleteDev(String equipId){
    public  Object deleteDev(List<String> list){
        Data data = new Data();
        for(String equipId:list) {
            if (activityDevMapper.deleteDev(equipId) == 0) {
                data.setState(false);
                data.setError("删除失败！无此设备。");
                return data;
            }
        }
        data.setState(true);
        return data;
    }

    public Object inputDevices(String parameter){
        Data data = new Data();
        if (parameter==null&&parameter.equals("")){
            data.setState(true);
            return data;
        }
        data.setState(true);
        data.setData(activityDevMapper.sleectInputDevices(parameter));
        return  data;
    }
    public Object inputVehicles(String name){
        Data data = new Data();
        if (name==null&&name.equals("")){
            data.setState(false);
            return data;
        }
        data.setState(true);
        data.setData(activityDevMapper.selectInputVehicles(name));
        return  data;
    }
}
